<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
	template="/WEB-INF/templates/business/supplier/template.xhtml">

	<f:metadata>
		<f:viewParam name="certId" value="#{unauditCertHome.id}"></f:viewParam>
		<f:event listener="#{unauditCertHome.initConversation()}"
			type="preRenderView"></f:event>
	</f:metadata>
	<ui:define name="supplier_head">
		<style type="text/css">
			.column1 {
				width: 10%;
			}
			
			.column2 {
				width: 90%;
			}
			
			.top-alignment {
				vertical-align: top;
			}
			.removeButton {
				float: right;
				margin-right: 20px;
			}
			
			td {
				padding-bottom: 10px;
			}
			
			label {
				font-weight: bold;
			}
			
			.photoItem {
				float: left;
			}
		</style>
	</ui:define>
	<ui:define name="supplier_content">
		<p:panel header="审核失败信息" rendered="#{not empty unauditCertHome.instance.currRejectRecord}">
		        <h:panelGrid columns="2" cellpadding="5">
		        	<p:outputLabel for="rejectTime" value="驳回日期" />				
					<h:outputText id="rejectTime" value="#{unauditCertHome.instance.currRejectRecord.rejectTime}"   >
						<f:convertDateTime  pattern="yyyy-MM-dd"/>
					</h:outputText>
					<p:outputLabel for="reason" value="驳回原因" />				
					<h:outputText id="reason" value="#{unauditCertHome.instance.currRejectRecord.reason}"   />
					
				</h:panelGrid>
		</p:panel>
		<h:form id="editForm">
			 <p:messages id="messages" closable="true"><p:autoUpdate/></p:messages>
			<p:panel id="certs" header="资质证书" style="margin-bottom:10px;">
				<p:outputPanel id="cert">
					<p:panelGrid>
						<p:row>
							<p:column>
								<p:outputLabel for="qualificationClass"
									value="资质类别" />
							</p:column>
							<p:column colspan="5">
								<p:selectOneMenu id="qualificationClass"
									value="#{unauditCertHome.instance.qualificationClass}" immediate="true">
									<f:selectItem itemLabel="请选择" itemValue="#{null}" />
									<f:selectItems value="#{qualificationClassList.resultList}"
										var="_qc" itemLabel="#{_qc.name}" itemValue="#{_qc}" />
									<f:converter converterId="entityConverter"></f:converter>
									<f:ajax render="cert"></f:ajax>
									<f:ajax event="change" listener="#{unauditCertHome.clearTemplateSectors()}" render="cert"></f:ajax>
								</p:selectOneMenu>
							</p:column>
						</p:row>
	
						<c:forEach items="#{unauditCertHome.instance.qualificationTemplates}"
							var="_qualificationTemplate" varStatus="_qtStatus">
							<p:row>
								<p:column>
									<p:outputLabel for="level_#{_qtStatus.index}"
										value="等级" />
								</p:column>
								<p:column>
									<p:selectOneMenu id="level_#{_qtStatus.index}"
										value="#{_qualificationTemplate.qualificationLevel}"
										required="true"
										widgetVar="level_#{_qtStatus.index}">
										<f:selectItem itemLabel="请选择" itemValue="#{null}" />
										<f:selectItems
											value="#{unauditCertHome.instance.qualificationClass.sortedLevelOptions}"
											var="_lo" itemLabel="#{_lo.name}" itemValue="#{_lo}"></f:selectItems>
										<f:converter converterId="entityConverter"></f:converter>
									</p:selectOneMenu>
								</p:column>
	
								<p:column>
									<p:outputLabel for="sector_#{_qtStatus.index}"
										value="行业范围" />
								</p:column>
								<p:column colspan="2">
									<p:inputText id="sector_#{_qtStatus.index}"
										value="#{_qualificationTemplate.getSectorNames()}"
										required="true" readonly="true"
										widgetVar="sector_#{_qtStatus.index}" />
									<p:commandButton oncomplete="PF('chooseSectorDialog').show();"
										value="选择" immediate="true"
										action="#{unauditCertHome.initRootNode()}"
										update="chooseSectorDialog">
										<f:setPropertyActionListener value="#{_qualificationTemplate}"
											target="#{unauditCertHome.currentQualificationTemplate}"></f:setPropertyActionListener>
										<f:setPropertyActionListener value="#{_qtStatus.index}"
											target="#{unauditCertHome.currentQualificationTemplateIndex}"></f:setPropertyActionListener>
									</p:commandButton>
								</p:column>
	
								<p:column>
									<p:commandButton value="加行"
										action="#{unauditCertHome.instance.addEmptyQualificationTemplate()}"
										update="certs" immediate="true"></p:commandButton>
									<p:commandButton value="删除"
										action="#{unauditCertHome.instance.removeQualificationTemplate(_qtStatus.index)}"
										update="certs" immediate="true"
										rendered="#{_qtStatus.index > 0}"></p:commandButton>
								</p:column>
							</p:row>
						</c:forEach>
	
						<p:row>
							<p:column>
								<p:outputLabel for="approveDate" value="批准时间" />
							</p:column>
							<p:column>
								<p:calendar id="approveDate"
									value="#{unauditCertHome.instance.approveDate}" required="true"
									pattern="yyyy-MM-dd" inputStyleClass="input-small"
									showOn="button" navigator="true" readonlyInput="true">
								</p:calendar>
							</p:column>
							<p:column>
								<p:outputLabel for="approveLicenseNo"
									value="批准文号/资质证书号" />
							</p:column>
							<p:column>
								<p:inputText id="approveLicenseNo"
									value="#{unauditCertHome.instance.approveLicenseNo}" required="true">
								</p:inputText>
							</p:column>
							<p:column>
								<p:outputLabel for="contactor" value="联系人" />
							</p:column>
							<p:column>
								<p:inputText id="contactor"
									value="#{unauditCertHome.instance.contactor}" required="true"
									styleClass="input-small">
								</p:inputText>
							</p:column>
						</p:row>
	
						<p:row>
							<p:column>
								<p:outputLabel for="contactorPhoneNumber"
									value="联系人电话" />
							</p:column>
							<p:column>
								<p:inputText id="contactorPhoneNumber"
									value="#{unauditCertHome.instance.contactorPhoneNumber}" required="true"
									styleClass="input-small">
								</p:inputText>
							</p:column>
							<p:column>
								<p:outputLabel for="allotedDate" value="有效日期" />
							</p:column>
							<p:column>
								<p:calendar id="allotedDate"
									value="#{unauditCertHome.instance.allotedDate}" required="true"
									pattern="yyyy-MM-dd" inputStyleClass="input-small"
									showOn="button" navigator="true" readonlyInput="true">
								</p:calendar>
							</p:column>
							<p:column>
								<p:outputLabel for="approveDepartmentName"
									value="资质审核机关" />
							</p:column>
							<p:column>
								<p:inputText id="approveDepartmentName"
									value="#{unauditCertHome.instance.approveDepartmentName}" required="true">
								</p:inputText>
							</p:column>
						</p:row>
	
						<p:row>
							<p:column>
								<p:outputPanel>
									<p:outputLabel for="certPhotos" value="单位资质证书" />
									<br />
													（扫描图片上传）
												</p:outputPanel>
							</p:column>
							<p:column colspan="6">
								<p:outputPanel>
									<p:fileUpload id="certPhotos" label="选择"
										mode="advanced" required="true" multiple="true"
										skinSimple="true" sizeLimit="#{1024 * 1024 * 3}"
										uploadLabel="上传" cancelLabel="取消"
										update="editForm:certPhotosList"
										fileUploadListener="#{unauditCertHome.uploadCertPhotos}"
										allowTypes="/(\.|\/)(jpe?g|png)$/" />
									<p:panel
										id="certPhotosList"
										widgetVar="certPhotosList">
										<div id="imgsPreview" >
											<p:dataList
												value="#{unauditCertHome.instance.certPhotos}"
												var="_photo"
												rendered="#{unauditCertHome.instance.certPhotos.size() > 0}"
												itemStyleClass="photoItem">
												<img  data-original="#{attachmentUtils.getFullPath(_photo)}" src="#{attachmentUtils.getFullPath(_photo)}"  width="240"/>

												<p:commandLink styleClass="closeBtn" action="#{unauditCertHome.removeCertPhoto(_photo)}" update="editForm:certPhotosList" immediate="true" ></p:commandLink>
											</p:dataList>
										</div>
										<div style="clear: both" />
									</p:panel>	
								</p:outputPanel>
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputLabel value="是否隐藏" />
							</p:column>
							<p:column colspan="5">
								<p:selectBooleanCheckbox id="hidden" value="#{unauditCertHome.instance.hidden}" styleClass="hiddenCheckbox"></p:selectBooleanCheckbox>
								<p:tooltip id="toolTipGrow" for="hidden" value="若选择隐藏信息，则可能无法被选取"
      									showEffect="clip" hideEffect="explode" position="right"/>
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:outputPanel>
			</p:panel>
			<p:commandButton id="submitBtn" action="#{unauditCertHome.saveAndFlush()}" rendered="#{unauditCertHome.managed}" value="重新提交审核"
				ajax="false" />
				<p:tooltip id="toolTipGrow1" for="submitBtn" value="请谨慎重新提交审核,在资质审核期间，会影响您的选取！"
      									showEffect="clip" hideEffect="explode" position="bottom"/>
      		
      		<p:commandButton  action="#{unauditCertHome.saveAndFlush()}" rendered="#{not unauditCertHome.managed}" value="保存"
				ajax="false" />							
			<p:commandButton action="#{unauditCertHome.delete()}" value="删除"
			ajax="false" />
			
			
			
			<p:commandButton action="#{unauditCertHome.cancel()}" value="取消"
				immediate="true"></p:commandButton>
		</h:form>
		
		<p:dialog
			id="chooseSectorDialog"
			widgetVar="chooseSectorDialog"
			width="640"
			height="480"
			modal="true"
		>
			<h:form>
				<p:panel>
					<f:facet name="header">选择行业</f:facet>

					<p:treeTable
						value="#{unauditCertHome.rootNodeMap[unauditCertHome.currentQualificationTemplateIndex]}"
						var="_sectorNode"
						rendered="#{not empty unauditCertHome.currentQualificationTemplate}"
						selectionMode="checkbox"
						selection="#{unauditCertHome.selectedNodeMap[unauditCertHome.currentQualificationTemplateIndex]}"
					>
						<p:column>
							<f:facet name="header">行业类别</f:facet>
							#{_sectorNode.name}
						</p:column>
					</p:treeTable>

					<f:facet name="footer">
						<p:commandButton
							value="确定"
							action="#{unauditCertHome.chooseSectors()}"
							update=":editForm:sector_#{unauditCertHome.currentQualificationTemplateIndex}"
							oncomplete="PF('chooseSectorDialog').hide();"
						/>
						<p:commandButton
							value="取消"
							onclick="PF('chooseSectorDialog').hide();"
						/>
					</f:facet>
				</p:panel>
			</h:form>
		</p:dialog>
	</ui:define>
</ui:composition>
